package nonDictionaryTokenAnalyzer;

import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import main.tokens;

public class MainProcessor 
{
	//private ArrayList<String> arlCodeFile;
	private ArrayList<tokens> arlTokenArray;
	
	private AbbreviationProcessor clsAProcessor;
	
	public MainProcessor(ArrayList<String> pCodeFile, ArrayList<tokens> pTokenArray)
	{
		//arlCodeFile = pCodeFile;
		arlTokenArray = pTokenArray;
		clsAProcessor = new AbbreviationProcessor(pCodeFile);
	}
	
	public ArrayList<tokens> nonDicTokenProcess()
	{
		String strCntToken = "";
		
		String s = "[a-z]+";
		Pattern pattern=Pattern.compile(s);
       
		for (int i = 0; i < arlTokenArray.size(); i ++)
		{
			 Matcher ma=pattern.matcher(arlTokenArray.get(i).getToken().toLowerCase());
		     if (ma.find())
		     {
		    	 strCntToken = ma.group();
		     }
		     		     
		     if (strCntToken.length() == 1)
		     {
		    	 // token length = 1, so abandon the token by setting state to -1
		    	 arlTokenArray.get(i).setState(-1);
		     }
		     else if(strCntToken.length() == 2) 
		     {
		    	 // token length = 2, so do the Abbreviation process
		    	 String strRtn = clsAProcessor.getProcessorResult(strCntToken, arlTokenArray.get(i));
		    	 if (!strRtn.trim().equals(""))
		    	 {
		    		 arlTokenArray.get(i).setResult(strRtn);
		    	 }
		     }
		     else
		     {
		    	 // token length > 2, so try to split token
		    	 
		     }
		}
		
		return arlTokenArray;
	}
}
